import { ref } from 'vue'
import { defineStore } from 'pinia'   
import { setItem, getItem, removeAllItem } from '@/utils/storage'  
import { getConfig } from "@/apis/system/config"
 
 
export const useAppStore = defineStore('apps', () => {  
   const config = ref(getItem('config') || '')
   const sidebarOpened = ref(true);
   const isRouteShow = ref(true)
   const getConfigData = () => {
        return new Promise((resolve, reject) => {
            getConfig().then((data) => {
                config.value = data
                setItem('config', data)  
                resolve(data)
            }).catch((err) => {
                reject(err)
            })
        })
    }

    const refreshView = () => {
        isRouteShow.value = false
        nextTick(() => {
            isRouteShow.value = true
        })
    }

    const triggerSidebarOpened = () => {
        sidebarOpened.value = !sidebarOpened.value;
    }
 
  return { 
    config,
    getConfigData,
    triggerSidebarOpened,
    sidebarOpened,
    refreshView,
    isRouteShow
  }
})
